package com.tencent.smtt.sdk.a;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.text.TextUtils;
import com.esri.core.geometry.ShapeModifiers;
import com.tencent.smtt.sdk.TbsConfig;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/* loaded from: classes2.dex */
public class d {

    /* loaded from: classes2.dex */
    public static class a {
        public int a = -1;
        public int b = -1;
        public String c = "";
        public String d = "0";
        public String e = null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes2.dex */
    public static class b {
        public String a;
        public String b;

        private b() {
            this.a = "";
            this.b = "";
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:39:0x0080, code lost:
        if (android.text.TextUtils.isEmpty(r0.a) == false) goto L61;
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x0082, code lost:
        r2.setClassName(r0.b, r0.a);
     */
    /* JADX WARN: Code restructure failed: missing block: B:62:0x00cc, code lost:
        if (android.text.TextUtils.isEmpty(r0.a) == false) goto L61;
     */
    /* JADX WARN: Code restructure failed: missing block: B:67:0x00e0, code lost:
        if (android.text.TextUtils.isEmpty(r0.a) == false) goto L61;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static int a(android.content.Context r7, java.lang.String r8, java.util.HashMap<java.lang.String, java.lang.String> r9, com.tencent.smtt.sdk.WebView r10) {
        /*
            Method dump skipped, instructions count: 329
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.a.d.a(android.content.Context, java.lang.String, java.util.HashMap, com.tencent.smtt.sdk.WebView):int");
    }

    /* JADX WARN: Can't wrap try/catch for region: R(12:1|2|3|(3:7|8|(8:10|11|12|(1:14)|15|(1:17)(1:21)|18|19))|25|11|12|(0)|15|(0)(0)|18|19) */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0026  */
    /* JADX WARN: Removed duplicated region for block: B:18:0x002c  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x002f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static int a(android.content.Context r4, java.lang.String r5, java.util.HashMap<java.lang.String, java.lang.String> r6, java.lang.String r7, com.tencent.smtt.sdk.WebView r8) {
        /*
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            r0.<init>()
            r1 = 0
            android.content.pm.PackageManager r2 = r4.getPackageManager()     // Catch: java.lang.Throwable -> L1d
            if (r2 == 0) goto L1d
            java.lang.String r3 = "com.tencent.mtt"
            android.content.pm.PackageInfo r2 = r2.getPackageInfo(r3, r1)     // Catch: java.lang.Throwable -> L1d
            if (r2 == 0) goto L1d
            int r2 = r2.versionCode     // Catch: java.lang.Throwable -> L1d
            r3 = 601000(0x92ba8, float:8.4218E-40)
            if (r2 <= r3) goto L1d
            r2 = 1
            goto L1e
        L1d:
            r2 = 0
        L1e:
            java.lang.String r3 = "UTF-8"
            java.lang.String r1 = java.net.URLEncoder.encode(r5, r3)     // Catch: java.lang.Exception -> L29
            if (r2 == 0) goto L27
            r5 = r1
        L27:
            r1 = r2
            goto L2a
        L29:
        L2a:
            if (r1 == 0) goto L2f
            java.lang.String r1 = ",encoded=1"
            goto L31
        L2f:
            java.lang.String r1 = ""
        L31:
            java.lang.String r2 = "mttbrowser://url="
            r0.append(r2)
            r0.append(r5)
            java.lang.String r5 = ",product="
            r0.append(r5)
            java.lang.String r5 = "TBS"
            r0.append(r5)
            java.lang.String r5 = ",packagename="
            r0.append(r5)
            java.lang.String r5 = r4.getPackageName()
            r0.append(r5)
            java.lang.String r5 = ",from="
            r0.append(r5)
            r0.append(r7)
            java.lang.String r5 = ",version="
            r0.append(r5)
            java.lang.String r5 = "3.6.0.1310"
            r0.append(r5)
            r0.append(r1)
            java.lang.String r5 = r0.toString()
            int r4 = a(r4, r5, r6, r8)
            return r4
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.a.d.a(android.content.Context, java.lang.String, java.util.HashMap, java.lang.String, com.tencent.smtt.sdk.WebView):int");
    }

    public static a a(Context context) {
        boolean z = context.getApplicationContext().getSharedPreferences("x5_proxy_setting", 0).getBoolean("qb_install_status", false);
        a aVar = new a();
        if (z) {
            return aVar;
        }
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = null;
            try {
                packageInfo = packageManager.getPackageInfo(TbsConfig.APP_QB, 0);
                aVar.a = 2;
                aVar.e = TbsConfig.APP_QB;
                aVar.c = "ADRQB_";
                if (packageInfo != null && packageInfo.versionCode > 420000) {
                    aVar.b = packageInfo.versionCode;
                    aVar.c += packageInfo.versionName.replaceAll("\\.", "");
                    aVar.d = packageInfo.versionName.replaceAll("\\.", "");
                    return aVar;
                }
            } catch (PackageManager.NameNotFoundException unused) {
            }
            try {
                try {
                    try {
                        try {
                            try {
                                packageInfo = packageManager.getPackageInfo("com.tencent.qbx", 0);
                                aVar.a = 0;
                                aVar.e = "com.tencent.qbx";
                                aVar.c = "ADRQBX_";
                            } catch (PackageManager.NameNotFoundException unused2) {
                                packageInfo = packageManager.getPackageInfo("com.tencent.mtt.x86", 0);
                                aVar.e = "com.tencent.mtt.x86";
                                aVar.a = 2;
                                aVar.c = "ADRQB_";
                            }
                        } catch (PackageManager.NameNotFoundException unused3) {
                            packageInfo = packageManager.getPackageInfo(TbsConfig.APP_QB, 0);
                            aVar.e = TbsConfig.APP_QB;
                            aVar.a = 2;
                            aVar.c = "ADRQB_";
                        }
                    } catch (Exception unused4) {
                        b a2 = a(context, Uri.parse("http://mdc.html5.qq.com/mh?channel_id=50079&u="));
                        if (a2 != null && !TextUtils.isEmpty(a2.b)) {
                            PackageInfo packageInfo2 = packageManager.getPackageInfo(a2.b, 0);
                            try {
                                aVar.e = a2.b;
                                aVar.a = 2;
                                aVar.c = "ADRQB_";
                            } catch (Exception unused5) {
                            }
                            packageInfo = packageInfo2;
                        }
                    }
                } catch (PackageManager.NameNotFoundException unused6) {
                    packageInfo = packageManager.getPackageInfo("com.tencent.qbx5", 0);
                    aVar.a = 1;
                    aVar.e = "com.tencent.qbx5";
                    aVar.c = "ADRQBX5_";
                }
            } catch (Exception unused7) {
            }
            if (packageInfo != null) {
                aVar.b = packageInfo.versionCode;
                aVar.c += packageInfo.versionName.replaceAll("\\.", "");
                aVar.d = packageInfo.versionName.replaceAll("\\.", "");
            }
        } catch (Exception unused8) {
        }
        return aVar;
    }

    private static b a(Context context, Uri uri) {
        Intent intent = new Intent("com.tencent.QQBrowser.action.VIEW");
        intent.setData(uri);
        List<ResolveInfo> queryIntentActivities = context.getPackageManager().queryIntentActivities(intent, 0);
        if (queryIntentActivities.size() <= 0) {
            return null;
        }
        b bVar = new b();
        for (ResolveInfo resolveInfo : queryIntentActivities) {
            String str = resolveInfo.activityInfo.packageName;
            if (str.contains(TbsConfig.APP_QB)) {
                bVar.a = resolveInfo.activityInfo.name;
                bVar.b = resolveInfo.activityInfo.packageName;
                return bVar;
            } else if (str.contains("com.tencent.qbx")) {
                bVar.a = resolveInfo.activityInfo.name;
                bVar.b = resolveInfo.activityInfo.packageName;
            }
        }
        return bVar;
    }

    public static boolean a(Context context, long j, long j2) {
        a a2 = a(context);
        boolean z = false;
        try {
            if (Long.valueOf(a2.d).longValue() >= j) {
                z = true;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        if (a2.b >= j2) {
            return true;
        }
        return z;
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0079 A[Catch: Exception -> 0x0082, TryCatch #0 {Exception -> 0x0082, blocks: (B:2:0x0000, B:4:0x0009, B:6:0x000f, B:7:0x0013, B:9:0x0019, B:11:0x002b, B:12:0x002f, B:15:0x0044, B:18:0x004d, B:20:0x0079, B:21:0x007e), top: B:26:0x0000 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public static boolean a(android.content.Context r5, java.lang.String r6, int r7, java.lang.String r8, java.util.HashMap<java.lang.String, java.lang.String> r9, android.os.Bundle r10) {
        /*
            android.content.Intent r0 = new android.content.Intent     // Catch: java.lang.Exception -> L82
            java.lang.String r1 = "com.tencent.QQBrowser.action.sdk.document"
            r0.<init>(r1)     // Catch: java.lang.Exception -> L82
            if (r9 == 0) goto L2f
            java.util.Set r1 = r9.keySet()     // Catch: java.lang.Exception -> L82
            if (r1 == 0) goto L2f
            java.util.Iterator r1 = r1.iterator()     // Catch: java.lang.Exception -> L82
        L13:
            boolean r2 = r1.hasNext()     // Catch: java.lang.Exception -> L82
            if (r2 == 0) goto L2f
            java.lang.Object r2 = r1.next()     // Catch: java.lang.Exception -> L82
            java.lang.String r2 = (java.lang.String) r2     // Catch: java.lang.Exception -> L82
            java.lang.Object r3 = r9.get(r2)     // Catch: java.lang.Exception -> L82
            java.lang.String r3 = (java.lang.String) r3     // Catch: java.lang.Exception -> L82
            boolean r4 = android.text.TextUtils.isEmpty(r3)     // Catch: java.lang.Exception -> L82
            if (r4 != 0) goto L13
            r0.putExtra(r2, r3)     // Catch: java.lang.Exception -> L82
            goto L13
        L2f:
            java.io.File r9 = new java.io.File     // Catch: java.lang.Exception -> L82
            r9.<init>(r6)     // Catch: java.lang.Exception -> L82
            java.lang.String r1 = "key_reader_sdk_id"
            r2 = 3
            r0.putExtra(r1, r2)     // Catch: java.lang.Exception -> L82
            java.lang.String r1 = "key_reader_sdk_type"
            r0.putExtra(r1, r7)     // Catch: java.lang.Exception -> L82
            r1 = 1
            if (r7 != 0) goto L48
            java.lang.String r7 = "key_reader_sdk_path"
        L44:
            r0.putExtra(r7, r6)     // Catch: java.lang.Exception -> L82
            goto L4d
        L48:
            if (r7 != r1) goto L4d
            java.lang.String r7 = "key_reader_sdk_url"
            goto L44
        L4d:
            java.lang.String r6 = "key_reader_sdk_format"
            r0.putExtra(r6, r8)     // Catch: java.lang.Exception -> L82
            android.net.Uri r6 = android.net.Uri.fromFile(r9)     // Catch: java.lang.Exception -> L82
            java.lang.StringBuilder r7 = new java.lang.StringBuilder     // Catch: java.lang.Exception -> L82
            r7.<init>()     // Catch: java.lang.Exception -> L82
            java.lang.String r9 = "mtt/"
            r7.append(r9)     // Catch: java.lang.Exception -> L82
            r7.append(r8)     // Catch: java.lang.Exception -> L82
            java.lang.String r7 = r7.toString()     // Catch: java.lang.Exception -> L82
            r0.setDataAndType(r6, r7)     // Catch: java.lang.Exception -> L82
            java.lang.String r6 = "loginType"
            android.content.Context r7 = r5.getApplicationContext()     // Catch: java.lang.Exception -> L82
            int r7 = d(r7)     // Catch: java.lang.Exception -> L82
            r0.putExtra(r6, r7)     // Catch: java.lang.Exception -> L82
            if (r10 == 0) goto L7e
            java.lang.String r6 = "key_reader_sdk_extrals"
            r0.putExtra(r6, r10)     // Catch: java.lang.Exception -> L82
        L7e:
            r5.startActivity(r0)     // Catch: java.lang.Exception -> L82
            return r1
        L82:
            r5 = move-exception
            r5.printStackTrace()
            r5 = 0
            return r5
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.smtt.sdk.a.d.a(android.content.Context, java.lang.String, int, java.lang.String, java.util.HashMap, android.os.Bundle):boolean");
    }

    public static boolean a(Context context, String str, HashMap<String, String> hashMap) {
        boolean z;
        Set<String> keySet;
        Uri parse = Uri.parse(str);
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setFlags(ShapeModifiers.ShapeHasIDs);
        intent.setDataAndType(parse, "video/*");
        if (hashMap != null && (keySet = hashMap.keySet()) != null) {
            for (String str2 : keySet) {
                String str3 = hashMap.get(str2);
                if (!TextUtils.isEmpty(str3)) {
                    intent.putExtra(str2, str3);
                }
            }
        }
        try {
            intent.putExtra("loginType", d(context));
            intent.setComponent(new ComponentName(TbsConfig.APP_QB, "com.tencent.mtt.browser.video.H5VideoThrdcallActivity"));
            context.startActivity(intent);
            z = true;
        } catch (Throwable unused) {
            z = false;
        }
        if (!z) {
            try {
                intent.setComponent(null);
                context.startActivity(intent);
            } catch (Throwable th) {
                th.printStackTrace();
                return false;
            }
        }
        return true;
    }

    private static boolean a(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        String trim = str.trim();
        int indexOf = trim.toLowerCase().indexOf("://");
        int indexOf2 = trim.toLowerCase().indexOf(46);
        if (indexOf <= 0 || indexOf2 <= 0 || indexOf <= indexOf2) {
            return trim.toLowerCase().contains("://");
        }
        return false;
    }

    public static boolean b(Context context) {
        return a(context).a != -1;
    }

    public static boolean c(Context context) {
        a a2 = a(context);
        boolean z = false;
        try {
            if (Long.valueOf(a2.d).longValue() >= 6001500) {
                z = true;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        if (a2.b >= 601500) {
            return true;
        }
        return z;
    }

    private static int d(Context context) {
        String str = context.getApplicationInfo().processName;
        if (str.equals(TbsConfig.APP_QQ)) {
            return 13;
        }
        if (str.equals(TbsConfig.APP_QZONE)) {
            return 14;
        }
        if (str.equals("com.tencent.WBlog")) {
            return 15;
        }
        return str.equals(TbsConfig.APP_WX) ? 24 : 26;
    }
}
